/**
 * DFS.java
 * 
 * @author Lex 2007-9-12 ����12:36:03
 */
package org.lex.utils.tree;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Iterator;

public class BFS<T> implements Iterator<T> {
	private Deque<Node> queue = null;

	public BFS(Node root) {
		this.queue = new ArrayDeque<Node>(2);
		this.queue.offerLast(root);
	}

	public boolean hasNext() {
		return false == queue.isEmpty();
	}

	public T next() {
		Node top = queue.pollFirst();
		int childCount = top.getChildCount();
		if (0 == childCount)
			return (T) top.getData();
		for (int i = 0; i < childCount; i++)
			queue.offerLast(top.getChildAt(i));
		return (T) top.getData();
	}

	public void remove() {
	}
}
